//
//  BIDHeadlineView.m
//  HJGJCommunity
//
//  Created by mal on 2017/5/18.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "BIDHeadlineView.h"

static int count = 0;

@interface BIDHeadlineView()
{
    NSArray *_dataSourceArr;
}
@end

@implementation BIDHeadlineView
@synthesize delegate;

- (void)awakeFromNib
{
    [super awakeFromNib];
    _contentView.hidden = YES;
    _contentView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureHandler:)];
    [_contentView addGestureRecognizer:tapGR];
    _flagLabel.layer.cornerRadius = 4.f;
    _flagLabel.layer.masksToBounds = YES;
    _flagLabel.layer.borderWidth = 1.f;
    _flagLabel.layer.borderColor = RGBACOLOR(71.f, 70.f, 68.f, 1.0f).CGColor;
}

- (void)prepareData:(NSArray *)arr
{
    _contentView.hidden = NO;
    _dataSourceArr = [[NSArray alloc] initWithArray:arr];
    [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(displayNotice) userInfo:nil repeats:YES];
}

-(void)displayNotice
{
    count++;
    if (count >= _dataSourceArr.count)
    {
        count=0;
    }
    CATransition *animation = [CATransition animation];
    animation.delegate = self;
    animation.duration = 0.3f ;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = YES;
    animation.type = @"cube";
    [_contentView.layer addAnimation:animation forKey:@"animationID"];
    _titleLabel.text = _dataSourceArr[count][@"title"];
}

- (void)tapGestureHandler:(UITapGestureRecognizer *)gr
{
    [delegate showHeadlineDetailWithDictionary:_dataSourceArr[count]];
}

@end
